import http from '@ohos.net.http'
import { Data } from '../types/Comm'
import { LoginResult } from '../types/member'

const baseURL = 'http://192.168.2.249:8080'

export const ht =(url: string, options: http.HttpRequestOptions):Promise<http.HttpResponse>=> {
  if (!url.startsWith('http')) {
    url = baseURL + url
  }

  options.header = {
    ...options.header,
    'source-client': "miniapp"
  }

  let memberStore: LoginResult = AppStorage.Get("memberStore")
  const token = memberStore?.token
  if (token) {
    options.header = {
      ...options.header,
      'Authorization': token
    }
  }

  return (http.createHttp().request(url, options))
}
